<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
${pu:reqSet('tempHql', 'from MemberMsgTemplate order by id asc') }
${pu:reqSet('templates', pu:queryByHql(tempHql, null, null)) }
<script>
$(function(){
	$('#list').click(function(){
		location.href='/ecadmin/memberMsg/list.do';
	});
});
function previewFormReset(){
	$('#iFrame').attr('src', '/ecadmin/jsp/blank.htm');
	$('#previewFrame').attr('src', '/ecadmin/jsp/blank.htm');
	$('#previewFrame').css('height', '0');
	$('#giveCoupon').hide();
	$('#giveBonus').hide();
	document.previewForm.coupon.disabled='disabled';
	document.previewForm.bonus.disabled='disabled';
	document.previewForm.coupon.value='';
	document.previewForm.bonus.value='';
	document.previewForm.reset();
	$('#previewZone').css('display', 'none');
}
function checkPreviewForm(){
	errorMsg="";
	if(document.previewForm.tempId.value==''){
		errorMsg+='请选择范本\r\n';
	}
	if(document.previewForm.file.value=='' && document.previewForm.orders.value==''){
		errorMsg+="请选择汇入的档案或填入订单号\r\n";
	}
	if(!document.previewForm.coupon.disabled && document.previewForm.coupon.value==''){
		errorMsg+='请填补偿礼券金额\r\n';
	}else if(isNaN(document.previewForm.coupon.value)){
		errorMsg+='补偿金额应为数字\r\n';
	}
	if(!document.previewForm.bonus.disabled && document.previewForm.bonus.value==''){
		errorMsg+='请填补偿积分\r\n';
	}else if(isNaN(document.previewForm.bonus.value)){
		errorMsg+='积分应为数字\r\n';
	}
	return errorMsg;
}
//IF PRERESULT HAS NO ERROR
function toPreviewPage(){
	$('#previewZone').show();
}
$(function(){
	previewFormReset();
	$('#preview').click(function(){
		$('#previewZone').hide();
		var errorMsg=checkPreviewForm();
		if(errorMsg!=''){
			alert(errorMsg);
		}else{
			document.previewForm.submit();
			document.previewPageForm.tempId.value=document.previewForm.tempId.value;
			$('.sendType').each(function(){
				if($(this).attr('checked')){
					document.previewPageForm.type.value=$(this).attr('value');
				}
			});
			document.previewPageForm.submit();
			//$('#previewZone').show();
		}
		
	});
	$('#reset').click(function(){
		previewFormReset();
	});
	$('#submit').click(function(){
		var errorMsg=checkPreviewForm();
		if(errorMsg!=''){
			alert(errorMsg);
		}else{
		$('#submit').hide();
		document.previewForm.action="/ecadmin/memberMsg/result.do";
		document.previewForm.target="_top";
		document.previewForm.submit();
		}
	});
	$('#tempId').change(function(){
		$('#giveCoupon').hide();
		$('#giveBonus').hide();
		document.previewForm.coupon.disabled='disabled';
		document.previewForm.bonus.disabled='disabled';
		document.previewForm.coupon.value='';
		document.previewForm.bonus.value='';
		
		<c-rt:forEach items="${templates}" var="template">
		<c-rt:if test="${template.isCoupon=='1' || template.isBonus=='1'}">
			if($(this).attr('value')=='${template.id}'){
				<c-rt:if test="${template.isCoupon=='1'}">
				$('#giveCoupon').show();
				document.previewForm.coupon.disabled='';
				</c-rt:if>
				<c-rt:if test="${template.isBonus=='1'}">
				$('#giveBonus').show();
				document.previewForm.bonus.disabled='';
				</c-rt:if>
			}
		</c-rt:if>
		</c-rt:forEach>
	});
});
function iframeHeight(){
	$('#previewFrame').css('height', previewFrame.document.body.clientHeight+60);
	
}

</script>

<br />
<h1>发送会员讯息

</h1>
<table width="100%">
<tr>
<td><div class="f-link"><a href="javascript:;" id="list">会员通知列表</a></div></td>
</tr>
</table>
<form action="/ecadmin/memberMsg/preResult.do" name="previewForm" id="previewForm" method="post" enctype="multipart/form-data" target="iFrame">
<table>
<tr>
<td>发送工具:
</td>
<td><input type="radio" name="type" value="1" class="sendType" checked="checked"/>系统信<input type="radio" name="type" value="2" class="sendType"/>短信</td>
</tr>
<tr>
<td>接收方:
</td>
<td><input type="radio" name="sendTo" value="memberReceiver" checked="checked"/>订购人<input type="radio" name="sendTo" value="orderReceiver" />收货人</td>
</tr>
<tr>
<td>选择范本:
</td>
<td>
<select name="tempId" id="tempId">
<option value="">请选择范本</option>
<c-rt:forEach items="${templates}" var="temp">
<option value="${temp.id }">${temp.title }</option>
</c-rt:forEach>
</select>
<span id="giveBonus"  style="display:none">
<input type="text" id="bonus" name="bonus" size="4"/>元
</span>
<span id="giveCoupon" style="display:none">
<input type="text" id="coupon" name="coupon" size="4"/>元
</span>
</td>
</tr>
<tr>
<td>发送时间:
</td>
<td>
<select name="sendTime">
<option value="0">即时发送</option>
<c-rt:forEach begin="1" end="12" varStatus="status">
<option value="${status.index }">${status.index }小时后</option>
</c-rt:forEach>
</select>
</td>
</tr>
<tr>
<td>

清单汇入(<a href="#" onclick="document.downloadOrderList.submit();return false;">下载清单格式</a>):

</td>
<td>
<input type="file" name="file"/> 
</td>
</tr>
<tr>
<td>或输入订单编号（以,分隔）:
</td>
<td>
<textarea name="orders" rows="2" cols="100" style="height:30px"></textarea>
</td>
</tr>

<tr>
<td><div class="f-link"><a href="javascript:;" id="preview">预览</a></div></td><td></td>
</tr>
</table>
</form>
<span id="previewZone" style="display:none">
<table width="100%" style="border:1px solid #000; cellspacing:5px;"><tr><td>
<iframe id="iFrame" name="iFrame" width="100%" height="150" frameborder="0" style="margin:10px">

</iframe>
</td></tr>
<tr><td>
<form name="previewPageForm" action="/ecadmin/memberMsg/preview.do" target="previewFrame">
<input type="hidden" name="tempId"/><input type="hidden" name="type"/>
</form>
<iframe id="previewFrame" name="previewFrame" width="100%" height="50" frameborder="0">

</iframe>
</td></tr></table>
<table>
<tr>
<td>
<div class="f-link"><a href="javascript:;" id="reset">重新选择</a></div><div class="f-link"><a href="javascript:;" id="submit">确认送出</a></div>
</td>
</tr>
</table>
</span>
<form name="downloadOrderList" method="post" action="/ecadmin/jsp/downloadOrderList.jsp">
	<input type="hidden" name="file" value="memberMsg.txt"/>
	<textarea name="content" style="display:none"><%="orderId1\r\norderId2\r\norderId3"%></textarea>
</form>
